<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <ul>
        <li>1</li>
        <li>2</li>
        <li>3</li>
        <li>4</li>
        <li>5</li>
    </ul>
    <script type="text/javascript">
        const lis = document.querySelectorAll("li");
        lis.forEach(function (item, index) {
            item.addEventListener("click", () => {
                console.log(index);
            })
        })
        console.log(lis);

        function test() {
            let arr = [];
            for (let i = 0; i < 10; i++) {
                (function (j) {
                    arr[j] = function () {
                        document.write(j + ' ')
                    }
                })(i);
            }
            return arr;
        }
        let myTest = test();
        for (let j = 0; j < 10; j++) {
            myTest[j]();
        }

        function add(num){
            let n = arguments[0] || 0;
            function ad(){
                n++;
                console.log(n);
            }
            return ad;
        }
        let ad = add(0);
        ad();
        ad();
        ad();
        ad();
    </script>
</body>

</html>